package guoanmaker.provider.business.controller;

import guoanmaker.provider.business.service.ProvideShopFollowService;
import guoanmaker.provider.helper.common.AjaxJson;
import guoanmaker.provider.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * DESC:
 * Created by JTing on 2017/12/17 10:19
 */
@RestController
@RequestMapping(ApiController.SHOP_URL)
public class ProvideShopFollowController {
    @Autowired
    private ProvideShopFollowService provideShopFollowService;

    /* *
     * @Description:关注/取消关注店铺
     * @author JTing
     * @date 2017/12/17 11:17
     * @param [shopId, userId, state]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "关注/取消关注店铺", notes = "关注/取消关注店铺")
    @PostMapping("/followOrNotFollow")
    public AjaxJson followOrNotFollow(String shopId, String userId, Integer state) {
    	AjaxJson ajaxJson=new AjaxJson();
        Map<String, Object> map = new HashMap<>();
        try {
            map = provideShopFollowService.followOrNotFollow(shopId, userId, state);
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(map);
        }
        return ajaxJson;
    }

    /* *
     * @Description:获取用户关注的店铺列表
     * @author JTing
     * @date 2017/12/17 11:18
     * @param [userId, page, pageSize]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "获取用户关注的店铺列表", notes = "获取用户关注的店铺列表")
    @PostMapping("/userShopFollowList")
    public AjaxJson userShopFollowList(String userId, Integer page, Integer pageSize) {
    	AjaxJson ajaxJson=new AjaxJson();
        Map<String, Object> map = new HashMap<>();
        try {
            map = provideShopFollowService.userShopFollowList(userId, page, pageSize);
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(map);
        }
        return ajaxJson;
    }

    @ApiOperation(value = "获取用户关注的店铺列表PC专用", notes = "获取用户关注的店铺列表PC专用")
    @PostMapping("/userShopFollowListForPc")
    public AjaxJson userShopFollowListForPc (String userId, Integer page, Integer pageSize) {
    	AjaxJson ajaxJson=new AjaxJson();
    	Map<String, Object> map = new HashMap<>();
        try {
            map = provideShopFollowService.userShopFollowListForPc(userId, page, pageSize);
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(map);
        }
        return ajaxJson;
    }

    @ApiOperation(value = "判断用户是否关注店铺", notes = "判断用户是否关注店铺")
    @PostMapping("/judgeUserIsFollow")
    public AjaxJson judgeUserIsFollow(String userId, String shopId) {
    	AjaxJson ajaxJson=new AjaxJson();
        Map<String, Object> map = new HashMap<>();
        try {
            map = provideShopFollowService.judgeUserIsFollow(userId, shopId);
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(map);
        }
        return ajaxJson;
    }
}
